<template>
  <el-container class="box">
    <!-- 头部导航 -->
    <el-header>
      <div class="header">
        <img class="logo" src="../assets/heima.png" alt />
        <span>后台管理系统</span>
        <el-button type="info" @click="logout">退出</el-button>
      </div>
    </el-header>
    <!-- 
    下边导航-->
    <el-container>
      <!-- 侧边导航 -->
      <el-aside :width="flag == false ? '200px' : '64px'" class="aside">
        <div class="shuxian" @click="flag = !flag">|||</div>
        <el-menu
          unique-opened
          :default-active="active"
          :collapse="flag"
          :collapse-transition="false"
          class="el-menu-vertical-demo"
          background-color="#363c42"
          text-color="#fff"
          active-text-color="#379aff"
          router
        >
          <el-submenu :index="item.id + ''" v-for="item in list" :key="item.id">
            <template slot="title">
              <i :class="iconObj[item.id]"></i>
              <span class="ico">{{ item.authName }}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item
              @click="actives('/' + sitem.path)"
              :index="'/' + sitem.path"
              v-for="sitem in item.children"
              :key="sitem.id"
            >
              <i class="el-icon-menu"></i>
              {{ sitem.authName }}
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>

      <!-- 主体内容 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: '',
  data() {
    return {
      active: '',
      flag: false,
      list: [],
      iconObj: {
        125: 'iconfont icon-user',
        103: 'iconfont icon-tijikongjian',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-danju',
        145: 'iconfont icon-baobiao',
      },
    }
  },
  created() {
    this.getlist()
    this.active = sessionStorage.getItem('active')
  },
  // mounted () {},
  computed: {},
  watch: {},
  methods: {
    //获取数据 赋值给list数组
    async getlist() {
      const { data: res } = await this.$http.get('menus')
      this.list = res.data
      // console.log(res.data);
    },
    logout() {
      // 1.清空token
      sessionStorage.clear()
      // 2.提示退出成功
      this.$message.success('退出成功')
      // 3.跳转到登录页
      this.$router.push('/login')
    },
    // 点击状态保持
    actives(path) {
      sessionStorage.setItem('active', path)
      this.active = path
    },
    //折叠侧边栏
    // zhedie() {
    //   this.flag = !this.flag;
    // }
  },
}
</script>

<style lang="less" scoped>
.box {
  height: 100% !important;
  .el-header {
    padding-left: 0;
    background-color: #363c42;
  }
  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .shuxian {
    height: 30px;
    line-height: 30px;
    cursor: pointer;
    text-align: center;
    letter-spacing: 3px;
    background-color: #495065;
    color: #ffffff;
  }
  .el-main {
    background-color: #e9edf1;
  }
  .el-aside {
    height: 100%;
    background-color: #363c42;
  }
  .el-menu-vertical-demo {
    border: 0;
  }
  .ico {
    margin-left: 10px;
  }
}
</style>
